<template>
	<view>
		<unifab v-if="!showNFC" @dragClick="qrcodeClick" marginLeft='-110rpx' imageBackgroundSize='100% 100%' width='220rpx' height='220rpx' creatTop="70" creatLeft="50" image="../../static/saoma.png" imageWidth="130upx"></unifab>
		<unifab v-if="showNFC" @dragClick="qrcodeNfcClick" marginLeft='-110rpx' imageBackgroundSize='100% 100%' width='220rpx' height='220rpx' creatTop="70" creatLeft="50" image="../../static/nfc.png" imageWidth="130upx"></unifab>
		<unifab @dragClick="refresh" creatTop="60" creatLeft="85" imageBackgroundSize='100% 100%'  width='100rpx' height='100rpx' image="../../static/refresh.png" imageWidth="60upx"></unifab>
		<unifab @dragClick="showGitee" creatTop="70" creatLeft="85" imageBackgroundSize='100% 100%' width='100rpx' height='100rpx' image="../../static/qiehuan.png" imageWidth="60upx"></unifab>
		<unifab @dragClick="jobOkList" creatTop="80" creatLeft="85" imageBackgroundSize='100% 100%' width='100rpx' height='100rpx' image="../../static/job.png" imageWidth="60upx"></unifab>
		<cu-custom bgColor="bg-gradual-blue" :isBack="false">
			<block slot="content">定期巡检</block>
		</cu-custom>
		<view class=""  style="margin-bottom: 110rpx;">
			<view class="page-box">
				<view class="cu-timeline">
					<view class="cu-time">
						<text class='cuIcon-selection text-white text-lg bg-blue round padding-xs'></text>
						<text class='text-xl margin-left'>{{JobName}}</text>
					</view>
				</view>
				<view v-if="showGetJobCompletionStatus" class="cu-timeline">
					<view class="cu-item text-blue" style="padding-top: 10rpx !important;">
						<view @click="goJobDetail()" class="goods-stock-wrap">
							<view class="goods-stock">已检/未检</view>
							<view class="goods-stock-isok">{{signed}}</view>
							<view class="goods-stock-middle">/</view>
							<view class="goods-stock-notok">{{notSigned}}</view>
						</view>
						<view @click="goJobDetail()" class="goods-stock-wrap">
							<view class="goods-stock">周期</view>
							<view class="goods-stock-font">{{qrcodeJobTask}}</view>
						</view>
						<view @click="goJobDetail()" class="goods-stock-wrap">
							<view class="goods-stock-right">查看计划完成情况</view>
						</view>
					</view>
				</view>
				<view class="cu-timeline" v-for="(res, index) in qrcodeList" :key="res.Id">
					<!--1 未签到, 2 签到中,3 已完结 -->
					<view class="cu-item" :class="res.scanStatus==1?'text-blue':res.scanStatus==2?'text-orange':'text-green'">
						<view class="content">
							<view class="cu-capsule radius">
								<view  @click="daoHang(res.qrcode_latitude,res.qrcode_longitude,res.qrcode_des)" class="cu-tag" :class="res.scanStatus==1?'bg-blue':res.scanStatus==2?'bg-orange':'bg-green'">{{res.qrcode_title}}</view>
								<!-- <view  @click="daoHang(res.qrcode_latitude,res.qrcode_longitude,res.qrcode_des)" :class="res.scanStatus==1?'line-blue':res.scanStatus==2?'line-orange':'line-green'" class="cu-tag">导航</view> -->
								<view class="cu-tag"></view>
								<view v-if="res.IsDetail==1&&res.scanStatus==3" style="margin-left: 20rpx;border-left: 1px solid;" @click="goTopic(res.SignId,res.scanStatus,0,res.Id,true)" :class="res.scanStatus==1?'line-blue':res.scanStatus==2?'line-orange':'line-green'" class="cu-tag">查看</view>
								<!-- 0  不需要签字，1 已经签字，2 还没签字 -->
								<view v-if="res.IsDetail==1&&res.scanStatus==3&&res.isSignature==2" style="margin-left: 20rpx;border-left: 1px solid;" @click="goSignature(res.SignId)" class="cu-tag line-orange">去签字</view>
								<view v-if="res.IsDetail==1&&res.scanStatus==3&&res.isSignature==1" style="margin-left: 20rpx;border-left: 1px solid;" @click="goSignatureDetail(res.SignSignatureImages)" class="cu-tag line-green">查看签字</view>
								
								<view v-if="res.scanStatus==1&&res.InspectionHandFill==1" style="margin-left: 20rpx;border-left: 1px solid;" @click="handleClick(res.Id)" class="cu-tag line-blue">去填写</view>
								<view v-if="res.IsDetail==1&&res.scanStatus==2" style="margin-left: 20rpx;border-left: 1px solid;" @click="goTopic(res.SignId,res.scanStatus,1,res.Id,false)" :class="res.scanStatus==1?'line-blue':res.scanStatus==2?'line-orange':'line-green'" class="cu-tag">{{res.isScan?'继续填写':'去填写'}}</view>
							</view>
							<view class="margin-top text-df text-black">描述：{{res.qrcode_des}}</view>
						</view>
					</view>
				</view>
				<view style="width: 100%;height: 200rpx;"></view>
			</view>
		</view>
		
		<!-- 切换巡检计划弹窗  :class="modalName=='ModalGitee'?'show':''"-->
		<view class="cu-modal" :class="modalName=='ModalGitee'?'show':''">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="content">选择巡检计划</view>
					<view class="action" @tap="hideModal">
						<text class="cuIcon-close text-red"></text>
					</view>
				</view>
				<view class="padding-xl">
					<view class="page-box">
						<view class="order" v-for="(res, index) in orderList" :key="res.Id">
							<view class="bottom">
								<view>
									<!-- text-blue 选中状态 -->
									<text :class="res.isChose?'text-blue':''" class="text-shadow">{{res.JobName}}</text>
									<!-- 团队巡检图标 -->
									<image
										v-if="res.IsTeam === 1"
										:src="tuanduiIcon"
										style="width: 40px; height: 25px; margin-left: 16rpx;top:12rpx"
									/>
									<!-- 个人巡检图标 -->
									<image
										v-if="res.IsTeam === 0"
										:src="gerenIcon"
										style="width: 40px; height: 25px; margin-left: 16rpx;top:12rpx"
									/>
								</view>
								
								<view class="btnBox">
									<!-- evaluate 选中状态 -->
									<view @click="goClass(res.Id,res.JobName,res.isNFC,res.isImages,res.isVideo,res.IsDeviceJob)" :class="res.isChose?'evaluate':''" class=" btn">{{res.isChose?'已选':'选择'}}</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view style="width: 100%;height: 300rpx;"></view>
	</view>
</template>

<script>
import unifab from "../../../components/beyondGod-drag/beyoundGod-drag.vue";	
import request from '@/common/request.js';
export default {
	components: {
			unifab
		},
	data() {
		return {
			adapter:null,
			nfcID:'',
			errCode:{
				13000: '本设备不支持NFC',
				13001: '系统NFC开关未打开',
				13010: '未知错误',
				13019: '用户未授权',
				13021: '已经开始NFC扫描',
				13018: '尝试在未开始NFC扫描时停止NFC扫描',
				13022: '标签已经连接',
				13023: '尝试在未连接标签时断开连接',
				13013: '未扫描到NFC标签',
				13014: '无效的标签技术',
				13015: '从标签上获取对应技术失败',
				13024: '当前标签技术不支持该功能',
				13017: '相关读写操作失败',
				13016: '连接失败'
			},
			showGetJobCompletionStatus:false,
			signed:0,
			notSigned:0,
			qrcodeJobTask:'',
			tuanduiIcon:request.baseUrl1+'/Resource/Sg/Scan/tuandui.png',
			gerenIcon:request.baseUrl1+'/Resource/Sg/Scan/geren.png',
			showNFC:false,
			scanData:{
				qrcodeId:'',
				jobId:'',
				longitude:'',
				latitude:''
			},
			savingRequestData:{
				qrcodeId:'',
				jobId:'',
				longitude:'',
				latitude:'',
				isCheckDevice:true,
				isNFC:false
			},
			reSavingRequestData:{
				signId:'',
				longitude:'',
				latitude:'',
				isNFC:false
			},
			isScan:true,
			modalName: null,
			orderList: [],
			requestData:{
				JobId:0
			},
			qrcodeList:[],
			JobName:'巡检计划',
			jobId:0
		};
	},
	onShow() {
		console.log('onShow-index')
		this.getQrcodeList();
	},
	onUnload() {
		console.log('onUnload-index')
	},
	onLoad(option) {
		console.log('onLoad-index')
		let that=this
		that.getQrcodeJobList();
	},
	mounted() {
		console.log('mounted-index')
		this.getQrcodeJobList();
		this.getJobCompletionStatus();
		this.checkNfcStatus()
	},
	beforeDestroy() {
	},
	computed: {
	},
	methods: {
		//自动选件巡检
		DirectInspection(InspectionQrcodeId){
			let that=this
			console.log('InspectionQrcodeId：'+InspectionQrcodeId)
			//走直接巡检逻辑
			uni.getStorage({
				key:'JobId',
				success(jobRes) {
					that.handleClick(InspectionQrcodeId)
				},fail(){
					//弹出选择计划框
					that.showGitee()
				}
			})
		},
		//巡检结束，进入这个方法，这样可以统一人脸相关的逻辑
		handleTopicSuccess(data) {
			// console.log("检测到从topic.vue返回，执行刷新操作");
			// console.log("值："+JSON.stringify(data));
			this.getQrcodeList();
			this.getJobCompletionStatus();
			
			//检测是否需要人脸校验
			this.ScanAfterFaceCheck(data.SignId);
		},
		ScanAfterFaceCheck(signId){
			let that=this
			uni.getStorage({
				key:'JobId',
				success(jobRes) {
					let jobId=jobRes.data.id
					let opts = {
						url: 'api/ScanAfterFaceCheck',
						method: 'get'
					};
					let requestData={
						jobId:jobId
					}
					request.httpTokenRequest(opts,requestData).then(res => {
						uni.hideLoading();
						if(res.data.code == 1){
							let isFace=res.data.data
							if(isFace){
								uni.navigateTo({
									url: '/pages-others/face/checkSignFace?signId='+signId
								})
							}
						}
						else{
							uni.showToast({ title: res.data.msg, icon: 'none' });
						}
					});
				}
			})
		},
		getJobCompletionStatus(){
			console.log('getJobCompletionStatus')
			let that=this
			uni.getStorage({
				key:'JobId',
				success(jobRes) {
					let jobId=jobRes.data.id
					let opts = {
						url: 'api/GetJobCompletionStatus',
						method: 'get'
					};
					let requestData={
						jobId:jobId
					}
					request.httpTokenRequest(opts,requestData).then(res => {
						uni.hideLoading();
						if(res.data.code == 1){
							that.showGetJobCompletionStatus=true
							that.signed=res.data.data.signed
							that.notSigned=res.data.data.notSigned
							that.qrcodeJobTask=res.data.data.qrcodeJobTask
						}
						else{
							uni.showToast({ title: res.data.msg, icon: 'none' });
						}
					});
				}
			})
		},
		//查看计划完成情况
		goJobDetail(){
			uni.getStorage({
				key:'JobId',
				success(jobRes) {
					console.log(JSON.stringify(jobRes))
					uni.navigateTo({
						url: '/pages-others/taskmanageDetail?jobId='+jobRes.data.id+'&JobName='+jobRes.data.jobname
					})
				},fail() {
					uni.showToast({ title:'请选择计划', icon: 'none' });
				}
			})
		},
		goTopic(SignId,scanStatus,showButton,qrcodeId,onlyShow){
			//去答题
			uni.getStorage({
				key:'JobId',
				success(jobRes) {
					let isDeviceJob=jobRes.data.isDeviceJob
					if(isDeviceJob==null||isDeviceJob==0){
						uni.navigateTo({
							url: '/pages/qrcode/qrcodejob/topic'+'?signid='+SignId+'&noJob=0&scanStatus='+scanStatus+'&showButton='+showButton+'&qrcodeid='+qrcodeId+'&onlyShow='+onlyShow
						})	
					}else{
						//去设备分类页面
						uni.navigateTo({
							url: '/pages-patrol/qrcodeDevicePatrol?qrcodeid='+qrcodeId+'&signid='+SignId+'&noJob=0'
						})
					}
				}
			})
		},
		goSignature(SignId){
			//去设备分类页面
			uni.navigateTo({
				url: '/pages-others/sign/goSignature?signId='+SignId
			})
		},
		goSignatureDetail(url){
			//url=url+'?imageMogr2/format/jpg/quality/30'
			let urls=[]
			urls.push(this.$request22.imageUrl+url)
			uni.previewImage({
				urls:urls
			});
		},
		daoHang(latitude,longitude,address){
			uni.openLocation({
				latitude: parseFloat(latitude),
				longitude: parseFloat(longitude),
				address: address,
				success: function() {
				},
				fail(err) {
					uni.showToast({ title:err, });
				}
			});
		},
		jobOkList(){
			uni.navigateTo({
				url: '/pages-others/mytask'
			})
		},
		refresh(){
			this.getQrcodeList();
			this.getJobCompletionStatus();
		},
		showGitee(e){
			this.modalName = 'ModalGitee'
			this.getQrcodeJobList();
		},
		hideModal(e) {
			this.modalName = ''
			this.orderList=[]
		},
		handleClick(qrcodeId){
			uni.showLoading({
				title: '提交中'
			})
			let that=this
			that.savingRequestData.qrcodeId=qrcodeId
			 
			//获取点位详情
			let opts111 = {
			 	url: 'api/GetQrcodeById',
			 	method: 'get'
			};
			let getQrcode={id:qrcodeId}
			 
			let newType=0;
			request.httpTokenRequest(opts111,getQrcode).then(qrcodeRes => {
				uni.hideLoading();
				if(qrcodeRes.data.code == 1){
					newType=qrcodeRes.data.data
					if(newType==2){
						// 跳转，传参
						uni.navigateTo({
							url:`/pages-device/repair/record?id=${qrcodeId}&type=${newType}`
						})
						return
					}
					uni.getStorage({
						key: 'JobId',
						success: function (res1) {
							that.savingRequestData.jobId=res1.data.id;
							let opts = {
								url: 'api/SavingQrcode',
								method: 'get'
							};
							uni.getLocation({
								type: 'gcj02',
								isHighAccuracy:true,
								success(res3) {
									that.savingRequestData.latitude = res3.latitude;
									that.savingRequestData.longitude = res3.longitude;
									request.httpTokenRequest(opts,that.savingRequestData).then(res => {
										if(res.data.code == 1){
											uni.hideLoading();
											if(res.data.data.firstGo=='goTopic'){
												//去答题
												uni.navigateTo({
													url: '/pages/qrcode/qrcodejob/topic?qrcodeid='+qrcodeId+'&signid='+res.data.msg+'&noJob=0'
												})
											}else if(res.data.data.firstGo=='goSecondDeviceTopic'){
												//去设备分类页面  二级设备巡检
												uni.navigateTo({
													url: '/pages-patrol/qrcodeDevicePatrol?qrcodeid='+qrcodeId+'&signid='+res.data.msg+'&noJob=0'
												})
											}else if(res.data.data.firstGo=='goPhone'){
												//去拍照1
												uni.navigateTo({
													url: '/pages/qrcode/qrcodejob/photo?qrcodeid='+qrcodeId+'&signid='+res.data.msg+'&noJob=0'
												})
											}else if(res.data.data.firstGo=='goDeviceDeatil'){
												//去设备详情页
												uni.navigateTo({
													url: '/pages/qrcode/qrcodejob/device?qrcodeid='+qrcodeId+'&secondGo='+res.data.data.secondGo+'&noJob=0'
												})
											}else{
												//直接结束
												uni.showToast({ title: '签到成功', icon: '/static/success.png' });
												let Qrcode_Topic_Back_Refresh={
													SignId:res.data.msg
												}
												that.handleTopicSuccess(Qrcode_Topic_Back_Refresh)
											}
										}
										else{
											uni.hideLoading();
											//特殊处理，如果是重复巡检，也就是code=399，需要告诉用户是否覆盖原有数据
											if(res.data.code == 399){
												let result399=res.data.data
												//去答题
												let showButton=0
												//1 未签到, 2 签到中,3 已完结
												let scanStatus=1
												//1 填报中，2 已完成
												if(result399.SignStatus==1){
													scanStatus=2
													showButton=1
												}
												if(result399.SignStatus==2){
													scanStatus=3
													showButton=0
													uni.showModal({
														title: '提示',
														content: '确认巡检完成了吗？',
														success: function (resSignOK) {
															if (resSignOK.confirm) {
																that.LeaveTimeSign(result399.signId, res3.longitude, res3.latitude)
															}
														}
													});
												}else{
													uni.navigateTo({
														url: '/pages/qrcode/qrcodejob/topic?qrcodeid='+qrcodeId+'&signid='+result399.signId+'&noJob=0&scanStatus='+scanStatus+'&showButton='+showButton
													})
												}
											}else if(res.data.code == 388){
												uni.showToast({ title:'您无需操作', icon: 'none' });
											}
											else{
												uni.showToast({ title: res.data.msg, icon: 'none' });
											}
										}
									});
								},
								fail: function () {
									uni.hideLoading();
									uni.showToast({
										title: '定位失败，请退出登陆重新开启定位',
										icon:'none',
										duration: 4000
									});
								}
							});
						},fail() {
							uni.hideLoading();
							uni.showToast({
								title: '请选择巡检计划',
								icon:'none',
								duration: 4000
							});
						}
					});
				}else
				{
					uni.showToast({ title: qrcodeRes.data.msg, icon: 'none' });
				}
			});
		},
		qrcodeClick() {
			uni.showLoading({
				title: '提交中'
			})
			let that = this;
			 // 只允许通过相机扫码
			 uni.scanCode({
				 onlyFromCamera: true,
				 success: function(res) {
					 that.result2 = res.result;
					 
					 let qrcodeId=request.getRequest(res.result,'id')
					 that.savingRequestData.qrcodeId=qrcodeId
					 
					//获取点位详情
					let opts111 = {
					 	url: 'api/GetQrcodeById',
					 	method: 'get'
					};
					let getQrcode={id:qrcodeId}
					 
					let newType=0;
					request.httpTokenRequest(opts111,getQrcode).then(qrcodeRes => {
						if(qrcodeRes.data.code == 1){
							newType=qrcodeRes.data.data
							if(newType==2){
								// 跳转，传参
								uni.navigateTo({
									url:`/pages-device/repair/record?id=${qrcodeId}&type=${newType}`
								})
								return
							}
							uni.getStorage({
								key: 'JobId',
								success: function (res1) {
									that.savingRequestData.jobId=res1.data.id;
									let opts = {
										url: 'api/SavingQrcode',
										method: 'get'
									};
									uni.getLocation({
										type: 'gcj02',
										isHighAccuracy:true,
										success(res3) {
											that.savingRequestData.latitude = res3.latitude;
											that.savingRequestData.longitude = res3.longitude;
											request.httpTokenRequest(opts,that.savingRequestData).then(res => {
												if(res.data.code == 1){
													uni.hideLoading();
													if(res.data.data.firstGo=='goTopic'){
														//去答题
														uni.navigateTo({
															url: '/pages/qrcode/qrcodejob/topic?qrcodeid='+qrcodeId+'&signid='+res.data.msg+'&noJob=0'
														})
													}else if(res.data.data.firstGo=='goSecondDeviceTopic'){
														//去设备分类页面
														uni.navigateTo({
															url: '/pages-patrol/qrcodeDevicePatrol?qrcodeid='+qrcodeId+'&signid='+res.data.msg+'&noJob=0'
														})
													}else if(res.data.data.firstGo=='goPhone'){
														//去拍照1
														uni.navigateTo({
															url: '/pages/qrcode/qrcodejob/photo?qrcodeid='+qrcodeId+'&signid='+res.data.msg+'&noJob=0'
														})
													}else if(res.data.data.firstGo=='goDeviceDeatil'){
														//去设备详情页
														uni.navigateTo({
															url: '/pages/qrcode/qrcodejob/device?qrcodeid='+qrcodeId+'&secondGo='+res.data.data.secondGo+'&noJob=0'
														})
													}else{
														//直接结束
														uni.showToast({ title: '签到成功', icon: '/static/success.png' });
														uni.getStorage({
															key: 'PageCur',
															success: function (respage) {
																setTimeout(() => {
																	 uni.reLaunch({
																		url: '/pages/index/tabbar?PageCur='+respage.data
																	 });
																}, 0)
															},fail() {
																setTimeout(() => {
																	 uni.reLaunch({
																		url: '/pages/index/tabbar?PageCur=search'
																	 });
																}, 0)
															}
														});
													}
												}
												else{
													uni.hideLoading();
													//特殊处理，如果是重复巡检，也就是code=399，需要告诉用户是否覆盖原有数据
													if(res.data.code == 399){
														let result399=res.data.data
														//去答题
														let showButton=0
														//1 未签到, 2 签到中,3 已完结
														let scanStatus=1
														//1 填报中，2 已完成
														if(result399.SignStatus==1){
															scanStatus=2
															showButton=1
														}
														if(result399.SignStatus==2){
															scanStatus=3
															showButton=0
															uni.showModal({
																title: '提示',
																content: '确认巡检完成了吗？',
																success: function (resSignOK) {
																	if (resSignOK.confirm) {
																		that.LeaveTimeSign(result399.signId, res3.longitude, res3.latitude)
																	}
																}
															});
														}else{
															uni.navigateTo({
																url: '/pages/qrcode/qrcodejob/topic?qrcodeid='+qrcodeId+'&signid='+result399.signId+'&noJob=0&scanStatus='+scanStatus+'&showButton='+showButton
															})
														}
													}else if(res.data.code == 388){
														uni.showToast({ title:'您无需操作', icon: 'none' });
													}
													else{
														uni.showToast({ title: res.data.msg, icon: 'none' });
													}
												}
											});
										},
										fail: function () {
											uni.hideLoading();
											uni.showToast({
												title: '定位失败，请退出登陆重新开启定位',
												icon:'none',
												duration: 4000
											});
										}
									});
								},fail() {
									uni.hideLoading();
									uni.showToast({
										title: '请选择巡检计划',
										icon:'none',
										duration: 4000
									});
								}
							});
						}else
						{
							uni.showToast({ title: qrcodeRes.data.msg, icon: 'none' });
						}
					});
				 },fail(scanFailErr) {
					uni.hideLoading();
					console.log(scanFailErr)
				 }
			 });
		},
		LeaveTimeSign(signId,longitude,latitude){
			var that = this;
			let opts = {
				url: 'api/LeaveTimeSign',
				method: 'get'
			};
			let params={
				signId:signId,
				longitude:longitude,
				latitude:latitude
			};
			request.httpTokenRequest(opts,params).then(res => {
				uni.hideLoading();
				if(res.data.code == 1){
					console.log("成功进来了")
					uni.showToast({ title: '成功', icon: 'success',duration:2000 });
					setTimeout(function() {
						that.refresh()
					}, 2000); 
				}
				else{
					uni.showToast({ title: res.data.msg, icon: 'none' });
				}
			});
		},
		goClass(id,jobname,isnfc,isImages,isVideo,isDeviceJob){
			let that=this
			that.modalName='null'
			that.orderList=[]
			that.jobId=id
			uni.setStorage({
				key:'JobId',
				data:{id:id,jobname:jobname,isnfc:isnfc,isImages:isImages,isVideo:isVideo,isDeviceJob:isDeviceJob},
				success() {
					//准备加载点位
					that.getQrcodeList();
					//修改图片
					if(isnfc===1){
						that.showNFC=true
					}else{
						that.showNFC=false
					}
					that.getJobCompletionStatus();
				}
			})
		},
		transition({ detail: { dx } }) {
			this.$refs.tabs.setDx(dx);
		},
		animationfinish({ detail: { current } }) {
			this.$refs.tabs.setFinishCurrent(current);
			this.swiperCurrent = current;
			this.current = current;
		},
		getQrcodeJobList(){
			let that=this
			let jobId=''
			
			that.orderList=[]
			let opts = {
				url: 'api/GetQrcodeJob',
				method: 'get'
			};
			request.httpTokenRequest(opts).then(res => {
				if(res.data.code == 1){
					uni.getStorage({
						key: 'JobId',
						success: function (res1) {
							jobId=res1.data.id;
							that.JobName=res1.data.jobname;
							
							
							for(let i = 0; i < res.data.data.length; i++) {
								let data = res.data.data[i];
								if(data.Id==jobId){
									data.isChose=true;
								}else{
									data.isChose=false;
								}
								that.orderList.push(data);
							}
							that.getQrcodeList();
						},fail() {
							if(res.data.data.length==1){
								//不展示弹出层，直接存缓存
								let jobId=res.data.data[0].Id
								let jobName=res.data.data[0].JobName
								let isnfc=res.data.data[0].isNFC
								let isImages=res.data.data[0].isImages
								let isVideo=res.data.data[0].isVideo
								let IsDeviceJob=res.data.data[0].IsDeviceJob
								uni.setStorage({
									key:'JobId',
									data:{id:jobId,jobname:jobName,isnfc:isnfc,isImages:isImages,isVideo:isVideo,isDeviceJob:IsDeviceJob},
									success() {
										//修改图片
										if(isnfc===1){
											that.showNFC=true
										}else{
											that.showNFC=false
										}
										that.getQrcodeList();
									}
								})
								return;
							}
							
							that.modalName = 'ModalGitee'
							
							for(let i = 0; i < res.data.data.length; i++) {
								let data = res.data.data[i];
								if(data.Id==jobId){
									data.isChose=true;
								}else{
									data.isChose=false;
								}
								that.orderList.push(data);
							}
						}
					});
				}
				else{
					uni.showToast({ title: res.data.msg, icon: 'none' });
				}
			});
		},
		getQrcodeList(){
			uni.showLoading({
				title: '加载中'
			})
			let that=this
			that.qrcodeList=[]
			uni.getStorage({
				key: 'JobId',
				success: function (res) {
					that.requestData.JobId=res.data.id;
					that.JobName=res.data.jobname
					let opts = {
						url: 'api/GetQrcode',
						method: 'get'
					};
					request.httpTokenRequest(opts,that.requestData).then(res => {
						
						uni.hideLoading();
						if(res.data.code == 1){
							that.qrcodeList=[]
							for(let i = 0; i < res.data.data.length; i++) {
								let data = res.data.data[i];
								that.qrcodeList.push(data);
							}
							uni.hideLoading();
						}
						else{
							uni.showToast({ title: res.data.msg, icon: 'none' });
						}
					});
				},fail() {
					uni.hideLoading();
					uni.showToast({ title:'请选择计划', icon: 'none' });
					return;
				}
			});
		},
		checkNfcStatus(){
			let that=this
			uni.getStorage({
				key: 'JobId',
				success: function (res1) {
					if(res1.data.isnfc===1){
						that.showNFC=true
					}else{
						that.showNFC=false
					}
				},fail() {
				}
			});
		},
		async qrcodeNfcClick(){
			//如果是新卡要开卡，如果不是直接巡检
			let e=0;
			try {
				uni.showLoading({
				  title: '请靠近 NFC 卡片'
				})
				this.adapter = wx.getNFCAdapter()
				console.log('adapter', this.adapter)
				await this._startDiscovery()
				const discovered = await this._onDiscovered()
				if (e === 0) {
				  await this.NFCread(discovered)
				} else {
				  await this.NFCwrite(discovered)
				}
				await this._shutDown()
				//uni.showToast({ title:  '巡检成功id='+this.nfcID,icon: 'none' });
				
				//去巡检
				await this.handleClick(this.nfcID)
			}catch (e) {
				// TODO handle the exception
				console.log('catch-e', e)
					
				await this._shutDown()
					
				const content = this.errCode[e.errCode]
				uni.showToast({
				  title: content || e.errMsg,
				  icon: 'none',
				  duration: 2000
				})
			}
		},
		// 开始监听
		_startDiscovery () {
		  return new Promise((resolve, reject) => {
			this.adapter.startDiscovery({
			  success: e => {
				console.log('开始监听贴卡', e)
				resolve()
			  },
			  fail: error => {
				// console.log('error', error)
				reject(error)
			  }
			})
		  })
		},
		
		// 监听
		_onDiscovered () {
		  return new Promise((resolve, reject) => {
			this.adapter.onDiscovered(
			  (this.onDiscoveredCallback = res => {
				console.log('读到卡片了', res)
				// console.log('卡-id', res.id)
				console.log('卡-id', this.buf2hex(res.id))
				this.nfcID=this.buf2hex(res.id)
				// 调用打卡接口
			
				resolve(res)
			  })
			)
		  })
		},
			
		// 关闭
		_shutDown () {
		  this.adapter.offDiscovered(this.onDiscoveredCallback)
		  console.log('offDiscovered-关闭读')
		  this.adapter.stopDiscovery()
		  console.log('stopDiscovery-结束')
		  uni.hideLoading()
		},
			
		// 读取
		NFCread (res) {
		  return new Promise((resolve, reject) => {
			if (res.messages) {
			  const payload = res.messages[0].records[0].payload
			  console.log('payload', payload)
			
			  const bufToString = this.arrayBufferToString(payload)
			  console.log('bufToString', bufToString)
			} else {
			  console.log('此卡无内容')
			}
			
			resolve()
		  })
		},
		
		// 写入
		NFCwrite (res) {
		  return new Promise((resolve, reject) => {
			if (res.techs.includes(this.adapter.tech.nfcA)) {
			  console.log('发现' + this.adapter.tech.nfcA + '卡')
			  const nfcA = this.adapter.getNfcA()
			
			  nfcA.connect({
				success: connectRes => {
				  console.log('设备已连接A', connectRes)
			
				  // 将字符串转成 ArrayBuffer 对象
				  const arrayBuffer = this.stringToArrayBuffer('123')
				  console.log('arrayBuffer', arrayBuffer)
			
				  nfcA.transceive({
					data: arrayBuffer,
					success: transceiveRes => {
					  console.log('发送数据成功, 接收数据如下:', transceiveRes)
					  resolve()
					},
					fail: function (transceiveErr) {
					  console.log('发送数据失败', transceiveErr)
					  reject(transceiveErr)
					}
				  })
				},
				fail: function (connectResErr) {
				  console.log('设备联接错误', connectResErr)
				  reject(connectResErr)
				}
			  })
			} else {
			  uni.showToast({
				title: '标题',
				icon: '不支持此NFC卡',
				duration: 2000
			  })
			  resolve()
			}
		  })
		},
			
		// 转16进制字符
		buf2hex (buffer) {
		  // buffer is an ArrayBuffer
		  return Array.prototype.map.call(new Uint8Array(buffer), x => ('00' + x.toString(16)).slice(-2)).join('')
		},
			
		stringToArrayBuffer (str) {
		  const buf = new ArrayBuffer(str.length)
		  const bufView = new Uint8Array(buf)
		  for (let i = 0, strLen = str.length; i < strLen; i++) {
			bufView[i] = str.charCodeAt(i)
		  }
		  return buf
		},
			
		arrayBufferToString (buffer) {
		  const data = this.buf2hex(buffer)
		  if (data.length % 2) return ''
			
		  let tmp = ''
		  for (let i = 0; i < data.length; i += 2) {
			tmp += '%' + data.charAt(i) + data.charAt(i + 1)
		  }
			
		  return decodeURI(tmp)
		}
	}
};
</script>

<style lang="scss" scoped>
/* #ifndef H5 */
page {
	height: 100%;
	background-color: #f2f2f2;
}
/* #endif */
</style>

<style lang="scss" scoped>
.page-box{
	overflow: hidden;
}
.cu-capsule{
	border-radius: 10rpx;
}
.cu-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
}

.cu-modal.show {
  display: flex;
}
.padding-xl{
	// height:auto;
	// padding: 10px 24px;
	max-height: 60vh; /* 内容区域最大高度 */
	overflow-y: auto; /* 内容超出时显示滚动条 */
	padding: 16px; /* 调整内边距 */
}
.cu-dialog{
	//height: auto;
	max-height: 80vh; /* 模态框整体最大高度 */
	overflow: hidden; /* 隐藏超出部分 */
}
.checkJob{
	width:80px;
	float:right;
}
.order {
	background-color: #ffffff;
	margin: 20rpx auto;
	border-radius: 20rpx;
	box-sizing: border-box;
	padding: 15rpx;
	font-size: 28rpx;
	.top {
		display: flex;
		justify-content: space-between;
		.left {
			display: flex;
			align-items: center;
			.store {
				margin: 0 10rpx;
				font-size: 34rpx;
				font-weight: bold;
			}
		}
		.right {
			color: $u-type-warning-dark;
			.progressBox{
				width: 150rpx;
				float: right;
				.btn {
					line-height: 52rpx;
					width: 140rpx;
					border-radius: 12rpx;
					border: 2rpx solid $u-tips-color;
					font-size: 26rpx;
					text-align: center;
					color: $u-tips-color;
				}
				.evaluate {
					color: $u-type-primary;
					border-color: $u-type-primary;
				}
			}
		}
	}
	.item {
		display: flex;
		margin: 20rpx 0 0;
		.left {
			margin-right: 20rpx;
			image {
				width: 260rpx;
				height: 190rpx;
				border-radius: 10rpx;
			}
		}
		.content {
			.title {
				font-size: 28rpx;
				line-height: 45rpx;
			}
			.type {
				margin: 6rpx 0;
				font-size: 24rpx;
				color: $u-tips-color;
				text-overflow: -o-ellipsis-lastline;
				overflow: hidden;
				text-overflow: ellipsis;
				display: -webkit-box;
				-webkit-line-clamp: 3;
				line-clamp: 3;
				-webkit-box-orient: vertical;
			}
			.delivery-time {
				color: #0081ff;
				font-size: 24rpx;
			}
		}
		.right {
			margin-left: 10rpx;
			padding-top: 20rpx;
			text-align: right;
			.decimal {
				font-size: 24rpx;
				margin-top: 4rpx;
			}
			.number {
				color: $u-tips-color;
				font-size: 24rpx;
			}
		}
	}
	.total {
		margin-top: 20rpx;
		text-align: right;
		font-size: 24rpx;
		.total-price {
			font-size: 32rpx;
		}
	}
	.bottom {
		line-height: 70rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		.btnBox{
			width: 150rpx;
			display: flex;
			justify-content: space-between;
			.btn {
				line-height: 52rpx;
				width: 140rpx;
				border-radius: 12rpx;
				border: 2rpx solid $u-tips-color;
				font-size: 26rpx;
				text-align: center;
				color: $u-tips-color;
			}
			.evaluate {
				color: $u-type-primary;
				border-color: $u-type-primary;
			}
		}
	}
}
.centre {
	text-align: center;
	margin: 200rpx auto;
	font-size: 32rpx;
	image {
		width: 300rpx;
		border-radius: 50%;
		margin: 0 auto;
	}
	.tips {
		font-size: 24rpx;
		color: #999999;
		margin-top: 20rpx;
	}
	.btn {
		margin: 80rpx auto;
		width: 200rpx;
		border-radius: 32rpx;
		line-height: 64rpx;
		color: #ffffff;
		font-size: 26rpx;
		background: linear-gradient(270deg, #1cbbb4 0%, #0081ff 100%);
	}
}
.wrap {
	display: flex;
	flex-direction: column;
	height: calc(100vh - var(--window-top));
	width: 100%;
}
.swiper-box {
	flex: 1;
}
.swiper-item {
	height: 100%;
}
.cu-timeline .cu-time {
		width: 100%;
		text-align: left;
		padding: 20rpx 0 20rpx 37rpx;
		font-size: 26rpx;
		color: #888;
		display: block;
	}

	.text-red,
	.line-red,
	.lines-red {
		color: #FF3434;
	}

	.margin-avatar {
		margin-left: -15rpx;
	}

	.margin-avatar-bottom {
		margin-bottom: 150rpx;
	}

	.line-blue-tuniao::after {
		border-color: #0070ff !important;
		color: #0070ff;
	}

	.resume {
		/* background: #f1f1f1; */
		padding-top: 10rpx;
		border-radius: 6rpx;
		display: block;
		color: #666;
		line-height: 1.6;
	}

	.resume+.resume {
		margin-top: 20rpx;
	}

	.resume2 {
		padding-top: 10rpx;
		border-radius: 6rpx;
		display: block;
		color: #666;
		line-height: 1.6;
	}

	.edit {
		position: fixed;
		width: 100rpx;
		height: 100rpx;
		bottom: 250rpx;
		right: 30rpx;
		z-index: 1;
		opacity: 0.8;
		border: 1px solid #189eff;
		border-radius: 100rpx;
		box-shadow: 0rpx 0rpx 6rpx rgba(24, 158, 255, 1);
		padding: 20rpx;
	}

	.love {
		position: fixed;
		width: 100rpx;
		height: 100rpx;
		bottom: 550rpx;
		right: 30rpx;
		z-index: 1024;
		opacity: 0.8;
		border: 1px solid #189eff;
		border-radius: 100rpx;
		box-shadow: 0rpx 0rpx 6rpx rgba(24, 158, 255, 1);
		padding: 20rpx;
	}

	.bg-img-cont {
		background-size: cover;
		background-position: center;
		background-repeat: no-repeat;
		height: 350rpx;
	}

	.share-png {
		width: 100rpx;
		height: 100rpx;
		margin: 0 auto;
	}

	.share-wechat {
		width: 35rpx;
		height: 35rpx;
		margin: 0 10rpx -4rpx 0;
		opacity: 0.5;
	}

	.button-no::after {
		border: none;
	}

	.title-pyq {
		background-image: -webkit-linear-gradient(0deg, #1b6cff, #1ca5ff);
		/*1B6CFF 1B42FF*/
		-webkit-background-clip: text;
		-webkit-text-fill-color: transparent;
		opacity: 0.5;
	}

	.edit-fixed {
		position: fixed;
		width: 100%;
		bottom: 48px;
		z-index: 1024;
		box-shadow: 0 1rpx 6rpx rgba(0, 0, 0, 0.1);
	}

	.button-no {
		border: none;
		width: 100%;
		height: 100%;
		background-color: rgba(0, 0, 0, 0);
	}

	.centre {
		text-align: center;
		margin: 200rpx auto;
		font-size: 32rpx;

		image {
			width: 300rpx;
			border-radius: 50%;
			margin: 0 auto;
		}

		.tips {
			font-size: 24rpx;
			color: #999999;
			margin-top: 20rpx;
		}

		.btn {
			margin: 80rpx auto;
			width: 200rpx;
			border-radius: 32rpx;
			line-height: 64rpx;
			color: #ffffff;
			font-size: 26rpx;
			background: linear-gradient(270deg, #1cbbb4 0%, #0081ff 100%);
		}
	}

	.wrap {
		display: flex;
		flex-direction: column;
		height: calc(100vh - var(--window-top));
		width: 100%;
	}

	.swiper-box {
		flex: 1;
	}

	.swiper-item {
		height: 100%;
	}
	
	
	.goods-stock-wrap {
		display: flex;
		color: #969696;
		font-size: 24rpx;
		margin-top: 20rpx;
	}
	.goods-stock-wrap {
		display: flex;
		color: #969696;
		font-size: 24rpx;
		margin-top: 20rpx;
	}
	
	.goods-stock {
		margin-right: 40rpx;
		font-size: 28rpx;
		color: #636571;
		line-height: 32rpx;
	}
	.goods-stock-isok{
		margin-right: 10rpx;
		font-size: 38rpx;
		color: #00B52A;
		line-height: 32rpx;
		font-weight: 700;
	}
	.goods-stock-middle{
		margin-right: 10rpx;
		font-size: 38rpx;
		color: #636571;
		line-height: 32rpx;
		font-weight: 700;
	}
	.goods-stock-notok{
		margin-right: 40rpx;
		font-size: 38rpx;
		color: #F53F3E;
		line-height: 32rpx;
		font-weight: 700;
	}
	.goods-stock-right{
		margin-right: 40rpx;
		font-size: 28rpx;
		color: #2979FF;
		line-height: 32rpx;
		right: 40rpx;
	}
	.goods-stock-font{
		margin-right: 40rpx;
		font-size: 28rpx;
		color: #636571;
		line-height: 32rpx;
		right: 40rpx;
	}
	.cu-item-nobefore{
		padding: 30rpx 30rpx 30rpx 120rpx;
		position: relative;
		display: block;
		z-index: 0;
	}
</style>
